package com.mingdao.lhy.controller;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttribute;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.mingdao.lhy.biz.WishFillingBiz;
import com.mingdao.lhy.pojo.Admission;
import com.mingdao.lhy.pojo.FiveYearPlan;
import com.mingdao.lhy.pojo.HighSchool;
import com.mingdao.lhy.pojo.HighSchoolWish;
import com.mingdao.lhy.pojo.MiddleSchoolWish;
import com.mingdao.lhy.pojo.NinePlusFive;
import com.mingdao.lhy.pojo.ResponseVo;
import com.mingdao.lhy.pojo.Score;
import com.mingdao.lhy.pojo.SignUpPageData;
import com.mingdao.lhy.pojo.SignUpStudent;
import com.mingdao.lhy.pojo.SpecialProjectAndArtSpecialty;
import com.mingdao.lhy.pojo.ThreeYearPlan;
import com.mingdao.lhy.pojo.WishAll;
import com.mingdao.lhy.pojo.WishFive;
import com.mingdao.lhy.pojo.WishFour;
import com.mingdao.lhy.pojo.WishOne;
import com.mingdao.lhy.pojo.WishSix;
import com.mingdao.lhy.pojo.WishThree;
import com.mingdao.lhy.pojo.WishTwo;
import com.mingdao.lhy.pojo.page.ArtSpecialtySignUp;
import com.mingdao.lhy.pojo.page.ChangePassword;
import com.mingdao.lhy.service.WishFillingService;

@Controller
@RequestMapping("/")
public class WishStudentController {

	private static Logger log = LoggerFactory.getLogger(WishStudentController.class);

	/**
	 * #特色艺体填报起止时间
	 */
	@Value("${tsyttbkssj}")
	private String tsyttbkssj;
	
	@Value("${tsyttbjssj}")
	private String tsyttbjssj;
	
	@Autowired
	private HttpServletRequest request;

	@Autowired
	private WishFillingService wishFillingService;

	@Autowired
	private WishFillingBiz wishFillingBiz;

	// @Autowired
	// private HttpSession session;

	// @Autowired
	// private StudentMapper studentMapper;

	/**
	 * 学生志愿填报登录页面（默认界面）
	 * 
	 * @return
	 */
	@RequestMapping("")
	public String index(Model model) {

		Date today = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		System.out.println("当前时间：" + sdf.format(today));

		// if(wishFillingBiz.isEffectiveDate(today, Constant.YTTC_START_TIME,
		// Constant.YTTC_END_TIME)) {
		//
		// }
		SignUpStudent student = new SignUpStudent();
		model.addAttribute("student", student);
		// session.setAttribute("student", student);
		// model.addAttribute("msg","");
		// wishFillingService.getAllHighSchool();
		return "loginStudent";
	}

	@RequestMapping(value = "/selectLogin")
	public String selectLogin(@RequestParam("goid") String goid) {

		if ("1".equals(goid)) {
			return "/signup/loginStSignUp";
		} else {
			return "loginStudentWish";
		}

	}

	@RequestMapping(value = "/transforms")
	public String indexTransform(Model model) {
		HttpSession session = wishFillingBiz.getSession();
		SignUpStudent student = (SignUpStudent) session.getAttribute("student");
		model.addAttribute("student", student);
		return "transform";
	}

	/**
	 * 安全退出，返回登录页面
	 * 
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping(value = "/loginOut", method = RequestMethod.POST)
	public String loginOut(@ModelAttribute("session") Session session, HttpServletRequest request) {

		// 清除session
		Enumeration<String> em = request.getSession().getAttributeNames();

		while (em.hasMoreElements()) {
			request.getSession().removeAttribute(em.nextElement().toString());

		}

		request.getSession().removeAttribute("session");
		request.getSession().removeAttribute("student");
		request.getSession().invalidate();

		return "redirect:" + "";

	}

	@RequestMapping("goGetHighSchoolMajor")
	@ResponseBody
	public List<SpecialProjectAndArtSpecialty> getHighSchoolMajor(@ModelAttribute(value = "schoolId") String schoolId,
			Model model) {
		List<SpecialProjectAndArtSpecialty> highSchools = wishFillingService.getMajorByHighSchoolId(schoolId);
		return highSchools;
	}

	@RequestMapping("goGetFiveYearPlanNormalMajor")
	@ResponseBody
	public List<FiveYearPlan> getFiveYearPlanNormalMajor(@ModelAttribute(value = "schoolId") String schoolId,
			Model model) {
		List<FiveYearPlan> fiveYearPlans = wishFillingService.getNormalMajorFiveYearPlanBySchoolId(schoolId);
		return fiveYearPlans;
	}

	@RequestMapping("goGetFiveYearPlanNotNormalMajor")
	@ResponseBody
	public List<FiveYearPlan> getFiveYearPlanNotNormalMajor(@ModelAttribute(value = "schoolId") String schoolId,
			Model model) {
		List<FiveYearPlan> fiveYearPlans = wishFillingService.getNotNormalMajorFiveYearPlanBySchoolId(schoolId);
		return fiveYearPlans;
	}

	@RequestMapping("goGetThreeYearPlanMajor")
	@ResponseBody
	public List<ThreeYearPlan> getThreeYearPlanMajor(@ModelAttribute(value = "schoolId") String schoolId, Model model) {
		List<ThreeYearPlan> threeYearPlans = wishFillingService.getMajorThreeYearPlanBySchoolId(schoolId);
		return threeYearPlans;
	}

	@RequestMapping("goGetNinePlusFiveMajor")
	@ResponseBody
	public List<NinePlusFive> getNinePlusFiveMajor(@ModelAttribute(value = "schoolId") String schoolId, Model model) {
		List<NinePlusFive> ninePlusFives = wishFillingService.getMajorNinePlusFiveBySchoolId(schoolId);
		return ninePlusFives;
	}

	/**
	 * 学生志愿填报登录验证页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "check", method = RequestMethod.POST)
	public String check(@ModelAttribute("student") SignUpStudent student, Model model, HttpServletResponse response) {

		HttpSession session = wishFillingBiz.getSession();

		log.debug("进入【学生志愿填报登录验证页面】");
		if (null == student || null == student.getBmh() || null == student.getPassword()) {
			log.error("没有收到有效的请求数据");
			model.addAttribute("msg", "没有收到有效的请求数据");
			return "loginStudentWish";
		}
		/**
		 * 根据报名号查询学生信息
		 */
		/**
		 * 判断当前登录学生是否有效（是否为州外学生，是的话不允许填报志愿）
		 */

		// 调用业务逻辑查询对应的学生信息
		SignUpStudent dbStudent = new SignUpStudent();
		dbStudent = wishFillingService.getStudentByBmh(student.getBmh());
		if (null == dbStudent) {
			log.error("没有找到指定报名号的学生");
			model.addAttribute("result", "没有找到指定报名号的学生，检查报名号");
			response.setCharacterEncoding("UTF-8");
			try {
				response.getWriter().write("<script>alert('没有找到指定的学生，检查报名号');</script>");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return "loginStudentWish";
		}

		/**
		 * 判断学生是否第一次登录（如果密码为空，或者和身份证后8位相同则是初次登录）
		 * 
		 * 如果是，跳转到修改密码界面，如果不是，则继续前进到志愿填报页面
		 */
		String sfzhLast8 = dbStudent.getSfzh().substring(10, 18);
		String dbPassword = dbStudent.getPassword();
		if (null == dbPassword || (dbPassword.equals(sfzhLast8) && dbPassword.equals(student.getPassword()))) {
			log.debug("学生初次登录 ，进入【密码修改页面】");
			model.addAttribute("student", dbStudent);
			session.setAttribute("student", dbStudent);
			// model.addAttribute("changePassword",new ChangePassword());
			return "changePasswd";

		}
		// dbStudent.setPassword(student.getPassword());
		// dbStudent.setXm("测试用户");
		// dbStudent.setBmh(student.getBmh());

		// 验证是否找到对应的学生
		// 并且输入的密码是否和查找到的学生密码是否一致
		if (null != dbStudent.getPassword() && dbStudent.getPassword().equals(student.getPassword())) {

			// 验证成功转到填报页面
			log.debug("验证【成功】");

			log.info(dbStudent.getBmh());
			log.debug(dbStudent.getSfzh());
			model.addAttribute("student", dbStudent);
			if (null == session) {
				session = wishFillingBiz.getSession();
			}
			session.setAttribute("student", dbStudent);

			// ResponseVo vo = new ResponseVo();
			// model.addAttribute("vo",vo);

			// 转到选择操作页面，根据页面选择再转向具体功能页面
			return "transform";
		} else {
			// 验证失败继续回到登录页面
			// Model model = new Model();
			log.debug("验证【失败】");

			model.addAttribute("result", "验证失败，报名号或密码不正确");
			response.setCharacterEncoding("UTF-8");
			try {
				response.getWriter().write("<script>alert('报名号或密码错');</script>");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			return "loginStudent";
		}

	}

	/**
	 * 填报志愿页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "wish", method = RequestMethod.POST)
	public String wish(Model model, SignUpStudent student) {
		HttpSession session = wishFillingBiz.getSession();
		if (null == session || null == session.getAttribute("student")) {
			session = null;
			log.error("用户未登录，请重新登录");
			return "redirect:/";
		}
		student = (SignUpStudent) session.getAttribute("student");

		log.debug("进入【志愿填报页面】");
		if (null == student || null == student.getBmh() || student.getBmh().isEmpty()) {
			// model.addAttribute("student",student);
			log.warn("学生信息为空，需要重新登录");
			return "loginStudent";
		}

		model.addAttribute("student", student);

		return "wishFillingStudent";
	}

	/**
	 * 高中志愿填报完成后提交保存志愿
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "saveHighSchoolWish", method = RequestMethod.POST)
	@ResponseBody
	public ResponseVo saveHighSchoolWish(@ModelAttribute("highSchoolWish") HighSchoolWish highSchoolWish, Model model) {
		ResponseVo vo = new ResponseVo();
		HttpSession session = wishFillingBiz.getSession();
		if (null == session || null == session.getAttribute("student")) {
			session = null;
			log.error("用户未登录，请重新登录");
			vo.setCode("error");
			vo.setMessage("用户未登录，请重新登录");
			vo.setUrl("/");
			return vo;
			// return "/";
		}

		SignUpStudent student = (SignUpStudent) session.getAttribute("student");

		if (null == highSchoolWish) {
			log.error("未接收到用户的志愿信息，返回志愿填报本页面");
			vo.setCode("stay");
			vo.setMessage("未接收到用户的志愿信息，返回志愿填报本页面");
			return vo;
			// return "/";
		}

		log.debug("填报志愿完成后提交保存志愿");
		// WishFillingOneTwoThree wishFillingOneTwoThree=new WishFillingOneTwoThree();
		// if (null == wishFillingOneTwoThree ||
		// wishFillingOneTwoThree.getBmh().isEmpty()) {
		if (null == student || student.getBmh().isEmpty()) {
			log.warn("没有接收到页面传回的志愿信息");
			model.addAttribute("msg", "没有接收到页面传回的志愿信息");
			vo.setCode("stay");
			vo.setMessage("没有接收到页面传回的志愿信息");
			return vo;
			// return "/";
		}

		/**
		 * 根据传回的学生报名号查找学生对应的报名信息
		 */
		SignUpStudent signUpStudent = wishFillingService.getStudentByBmh(student.getBmh());
		if (null == signUpStudent) {
			log.warn("没有找到对应报名号的学生信息");
			model.addAttribute("msg", "没有找到对应报名号的学生信息");
			vo.setCode("error");
			vo.setMessage("没有找到对应报名号的学生信息");
			vo.setUrl("/");
			return vo;
			// return "/";
		}
		/**
		 * 对接收到的志愿信息合理性进行验证 TODO
		 */
		WishAll wa = (WishAll) session.getAttribute("wishAll");
		if (null == wa) {
			log.warn("没有找到对应报名学校信息");
			vo.setCode("error");
			vo.setMessage("没有找到对应报名学校信息");
			vo.setUrl("/");
			return vo;
		}
		Boolean checkOne = true;
		Boolean checkTwo = true;
		Boolean checkThree = true;
		Map<String, String> oneMap = new HashMap<String, String>();
		Map<String, String> twoMap = new HashMap<String, String>();
		Map<String, String> threeMap = new HashMap<String, String>();
		Map<String, String> oneClassMap = new HashMap<String, String>();
		Map<String, String> artMap = new HashMap<String, String>();
		Map<String, String> specMap = new HashMap<String, String>();

		if (null != wa.getWishOne().getHsList()) {
			for (int i = 0; i < wa.getWishOne().getHsList().size(); i++) {
				oneMap.put(wa.getWishOne().getHsList().get(i).getXxdm(), wa.getWishOne().getHsList().get(i).getXxmc());
			}
		}

		if (null != wa.getWishOne().getSpecialtyOfArts()) {
			for (int i = 0; i < wa.getWishOne().getSpecialtyOfArts().size(); i++) {
				artMap.put(wa.getWishOne().getSpecialtyOfArts().get(i).getYttcdm(),
						wa.getWishOne().getSpecialtyOfArts().get(i).getXxdm());
			}
		}

		if (null != wa.getWishOne().getFeaturedItems()) {
			for (int i = 0; i < wa.getWishOne().getFeaturedItems().size(); i++) {
				specMap.put(wa.getWishOne().getFeaturedItems().get(i).getTsxmdm(),
						wa.getWishOne().getFeaturedItems().get(i).getXxdm());
			}
		}
		if (null != wa.getWishOne().getOneClassOfSystems()) {
			for (int i = 0; i < wa.getWishOne().getOneClassOfSystems().size(); i++) {
				oneClassMap.put(wa.getWishOne().getOneClassOfSystems().get(i).getXxdm(),
						wa.getWishOne().getOneClassOfSystems().get(i).getXxmc());
			}
		}

		/**
		 * 第一批志愿高中学校代码
		 */
		/**
		 * 特色项目志愿
		 */
		if (null == oneMap.get(highSchoolWish.getGzy10()) && null != highSchoolWish.getGzy10()
				&& !highSchoolWish.getGzy10().isEmpty()) {
			checkOne = false;
		}
		if (null == specMap.get(highSchoolWish.getGtszy()) && null != highSchoolWish.getGtszy()
				&& !highSchoolWish.getGtszy().isEmpty()) {
			checkOne = false;
		}
		/**
		 * 艺体特长志愿
		 */
		if (null == oneMap.get(highSchoolWish.getGzy11()) && null != highSchoolWish.getGzy11()
				&& !highSchoolWish.getGzy11().isEmpty()) {
			checkOne = false;
		}
		if (null == artMap.get(highSchoolWish.getGytzy()) && null != highSchoolWish.getGytzy()
				&& !highSchoolWish.getGytzy().isEmpty()) {
			checkOne = false;
		}
		/**
		 * 一类体制志愿
		 */
		if (null == oneClassMap.get(highSchoolWish.getGylzy()) && null != highSchoolWish.getGylzy()
				&& !highSchoolWish.getGylzy().isEmpty()) {
			checkOne = false;
		}
		if (!checkOne) {
			log.warn("填报的第一批次学校或专业信息不匹配");
			vo.setCode("error");
			vo.setMessage("填报的第一批次学校或专业信息不匹配");
			vo.setUrl("/");
			return vo;
		}

		if (null != wa.getWishTwo().getHsList()) {
			for (int i = 0; i < wa.getWishTwo().getHsList().size(); i++) {
				twoMap.put(wa.getWishTwo().getHsList().get(i).getXxdm(), wa.getWishTwo().getHsList().get(i).getXxmc());
			}
		}

		/**
		 * 第二批次第一志愿
		 */
		if (null == twoMap.get(highSchoolWish.getGzy21()) && null != highSchoolWish.getGzy21()
				&& !highSchoolWish.getGzy21().isEmpty()) {
			checkTwo = false;
		}
		/**
		 * 第二批次第二志愿
		 */
		if (null == twoMap.get(highSchoolWish.getGzy22()) && null != highSchoolWish.getGzy22()
				&& !highSchoolWish.getGzy22().isEmpty()) {
			checkTwo = false;
		}
		/**
		 * 第二批次第三志愿
		 */
		if (null == twoMap.get(highSchoolWish.getGzy23()) && null != highSchoolWish.getGzy23()
				&& !highSchoolWish.getGzy23().isEmpty()) {
			checkTwo = false;
		}
		/**
		 * 第二批次第四志愿
		 */
		if (null == twoMap.get(highSchoolWish.getGzy24()) && null != highSchoolWish.getGzy24()
				&& !highSchoolWish.getGzy24().isEmpty()) {
			checkTwo = false;
		}
		if (!checkTwo) {
			log.warn("填报的第二批次学校或专业信息不匹配");
			vo.setCode("error");
			vo.setMessage("填报的第二批次学校或专业信息不匹配");
			vo.setUrl("/");
			return vo;
		}

		if (null != wa.getWishThree().getHsList()) {
			for (int i = 0; i < wa.getWishThree().getHsList().size(); i++) {
				threeMap.put(wa.getWishThree().getHsList().get(i).getXxdm(),
						wa.getWishThree().getHsList().get(i).getXxmc());
			}
		}

		/**
		 * 第三批次第一志愿
		 */
		if (null == threeMap.get(highSchoolWish.getGzy31()) && null != highSchoolWish.getGzy31()
				&& !highSchoolWish.getGzy31().isEmpty()) {
			checkThree = false;
		}
		/**
		 * 第三批次第二志愿
		 */
		if (null == threeMap.get(highSchoolWish.getGzy32()) && null != highSchoolWish.getGzy32()
				&& !highSchoolWish.getGzy32().isEmpty()) {
			checkThree = false;
		}
		/**
		 * 第三批次第三志愿
		 */
		if (null == threeMap.get(highSchoolWish.getGzy33()) && null != highSchoolWish.getGzy33()
				&& !highSchoolWish.getGzy33().isEmpty()) {
			checkThree = false;
		}
		/**
		 * 第三批次第四志愿
		 */
		if (null == threeMap.get(highSchoolWish.getGzy34()) && null != highSchoolWish.getGzy34()
				&& !highSchoolWish.getGzy34().isEmpty()) {
			checkThree = false;
		}
		if (!checkThree) {
			log.warn("填报的第三批次学校或专业信息不匹配");
			vo.setCode("error");
			vo.setMessage("填报的第三批次学校或专业信息不匹配");
			vo.setUrl("/");
			return vo;
		}

		/**
		 * 根据查找到的报名信息和画面传回的志愿信息填写志愿保存数据
		 */
		wishFillingBiz.setHighSchoolWish(signUpStudent, highSchoolWish);
		wishFillingBiz.checkHighSchoolWish(highSchoolWish);
		model.addAttribute("highSchoolWish", highSchoolWish);

		/**
		 * 保存志愿数据
		 */
		wishFillingService.saveHighSchoolWish(highSchoolWish);

		/**
		 * 跳转到完成页面
		 */
		model.addAttribute("signUpStudent", signUpStudent);
		// model.addAttribute("wishFillingOneTwoThree", wishFillingOneTwoThree);
		// return wishFillingBiz.getCurrentUrl(request);
		vo.setCode("ok");
		vo.setMessage("志愿保存成功");
		vo.setUrl("/transforms");
		return vo;
		// return "transform";
	}

	/**
	 * 中职志愿填报完成后提交保存志愿
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "saveMiddleSchoolWish", method = RequestMethod.POST)
	@ResponseBody
	public ResponseVo saveMiddleSchoolWish(@ModelAttribute("wish") MiddleSchoolWish wish, Model model) {
		ResponseVo vo = new ResponseVo();
		HttpSession session = wishFillingBiz.getSession();
		if (null == session || null == session.getAttribute("student")) {
			session = null;
			log.error("用户未登录，请重新登录");
			// return "redirect:/";
			vo.setCode("error");
			vo.setMessage("用户未登录，请重新登录");
			vo.setUrl("/");
			return vo;
		}
		if (null == wish) {
			log.error("未收到志愿数据为空，请重新填写");
			vo.setCode("stay");
			vo.setMessage("未接收到用户的志愿信息，返回志愿填报本页面");
			return vo;
		}
		SignUpStudent student = (SignUpStudent) session.getAttribute("student");
		if (null == student) {
			log.error("用户信息为空，请重新登录");
			vo.setCode("error");
			vo.setMessage("户信息为空，请重新登录");
			vo.setUrl("/");
			return vo;
		}

		wish.setBmh(student.getBmh());
		wish.setXm(student.getXm());

		model.addAttribute("student", student);

		log.debug("中职志愿填报完成后提交保存志愿");

		/**
		 * 对接收到的志愿填报信息进行有效性检查，防止前台篡改数据
		 */
		WishAll wa = (WishAll) session.getAttribute("wishAll");
		if (null == wa) {
			log.warn("没有找到对应报名学校信息");
			vo.setCode("error");
			vo.setMessage("没有找到对应报名学校信息");
			vo.setUrl("/");
			return vo;
		}
		Boolean checkFour = true;
		Map<String, String> fourMap = new HashMap<String, String>();

		if (null != wa.getWishFour().getZzList()) {
			for (int i = 0; i < wa.getWishFour().getZzList().size(); i++) {
				fourMap.put(wa.getWishFour().getZzList().get(i).getXxdm(),
						wa.getWishFour().getZzList().get(i).getXxmc());
			}
		}

		/**
		 * 第四批次第一志愿
		 */
		if (null == fourMap.get(wish.getZzy11()) && null != wish.getZzy11() && !wish.getZzy11().isEmpty()) {
			checkFour = false;
		}
		/**
		 * 第四批次第二志愿
		 */
		if (null == fourMap.get(wish.getZzy12()) && null != wish.getZzy12() && !wish.getZzy12().isEmpty()) {
			checkFour = false;
		}
		/**
		 * 第四批次第三志愿
		 */
		if (null == fourMap.get(wish.getZzy13()) && null != wish.getZzy13() && !wish.getZzy13().isEmpty()) {
			checkFour = false;
		}

		if (!checkFour) {
			log.warn("填报的第四批次学校或专业信息不匹配");
			vo.setCode("error");
			vo.setMessage("填报的第四批次学校或专业信息不匹配");
			vo.setUrl("/");
			return vo;
		}

		int result = wishFillingService.saveMiddleSchoolWish(wish);
		if (1 != result) {
			log.warn("志愿保存失败，请重新保存");
			vo.setCode("error");
			vo.setMessage("志愿保存失败，请重新保存");
			vo.setUrl("/transform");
			return vo;
		}

		// return "transform";
		vo.setCode("ok");
		vo.setMessage("志愿保存成功");
		vo.setUrl("/transforms");
		return vo;
	}

	/**
	 * 操作导航页面
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "transform2", method = RequestMethod.POST)
	public String finsh(@ModelAttribute("option") String option, Model model) {
		HttpSession session = wishFillingBiz.getSession();
		if (null == session || null == session.getAttribute("student")) {
			session = null;
			log.error("用户未登录，请重新登录");
			return "redirect:/";
		}
		SignUpStudent student = (SignUpStudent) session.getAttribute("student");

		/**
		 * 根据选择情况返回不同功能页面
		 */
		if (null == option || option.isEmpty()) {
			log.error("没有收到请求参数");
			return "transform";
		}
		/**
		 * 查询成绩操作
		 */
		if ("1".equals(option)) {

		} else
		/**
		 * 查询录取状态操作
		 */
		if ("2".equals(option)) {

		} else
		/**
		 * 特色项目及艺体特长报名
		 */
		if ("3".equals(option)) {
			log.debug("跳转到特色项目及艺体特长报名");
			return "forward:/artSpecialtySignUp";
		} else
		/**
		 * 高中（第一、二、三批次）志愿填报
		 */
		if ("4".equals(option)) {
			log.debug("跳转到高中（第一、二、三批次）志愿填报");
			return "forward:/wishOneTwoThreeSignUp";

		} else
		/**
		 * 中职（第四、五、六批次）志愿填报
		 */
		if ("5".equals(option)) {
			log.debug("跳转到中职（第四、五、六批次）志愿填报");
			return "forward:/wishFourFiveSixSignUp";

		} else {
			log.error("无效的参数");
			return "transform";
		}
		/**
		 * 保存根据学生查询的志愿数据传递到页面
		 */
		model.addAttribute("wishAll", wishFillingBiz.getWishByStudent(student));

		return "transform";
	}

	@RequestMapping(value = "goChangePasswd", method = RequestMethod.POST)
	public String goChangePwd(Model model) {
		HttpSession session = wishFillingBiz.getSession();
		if (null == session || null == session.getAttribute("student")) {
			session = null;
			log.error("用户未登录，请重新登录");
			return "redirect:/";
		}
		SignUpStudent student = (SignUpStudent) session.getAttribute("student");
		model.addAttribute("student", student);
		return "changePasswd";
	}

	@RequestMapping(value = "doChangePasswd", method = RequestMethod.POST)
	public String changePwd(@ModelAttribute(value = "changePassword") ChangePassword changePassword,
			@SessionAttribute SignUpStudent student, Model model) {

		HttpSession session = wishFillingBiz.getSession();
		if (null == session || null == session.getAttribute("student")) {
			session = null;
			log.error("用户未登录，请重新登录");
			return "redirect:/";
		}
		student = (SignUpStudent) session.getAttribute("student");
		/**
		 * 判断传入的密码
		 */
		if (null == model || null == model.asMap() || null == model.asMap().get("changePassword")) {
			log.error("未取到前台返回的密码值 ");
			model.addAttribute("msg", "未取到前台返回的密码值");
			// model.addAttribute("student", student);
			return "changePasswd";
		}
		// SignUpStudent student1 = (SignUpStudent) model.asMap().get("student");
		ChangePassword cp = (ChangePassword) model.asMap().get("changePassword");
		if (null == cp.getOldPassword()) {
			log.error("必须输入原来的密码值 ");
			model.addAttribute("msg", "必须输入原来的密码值");
			// model.addAttribute("student", student);
			return "check";
		}
		if (null == cp.getNewPasswordOne() || null == cp.getNewPasswordTwo()) {
			log.error("必须输入新的码值 ");
			model.addAttribute("msg", "必须输入新的码值");
			// model.addAttribute("student", student);
			return "changePasswd";
		}

		String oldPassword = cp.getOldPassword();
		String newPasswordOne = cp.getNewPasswordOne();
		String newPasswordTwo = cp.getNewPasswordTwo();

		/**
		 * 如果输入的旧密码等于学生本来的旧密码才可以更换密码
		 */
		if (!oldPassword.isEmpty() && !student.getPassword().isEmpty()) {
			if (oldPassword.equals(student.getPassword())) {
				/**
				 * 两次输入密码要一致才有效
				 */
				if (newPasswordOne.equals(newPasswordTwo)) {
					student.setPassword(newPasswordOne);
				} else {
					log.error("两次密码不符，请重新核对 ");
					model.addAttribute("msg", "两次密码不符，请重新核对 ");
					model.addAttribute("student", student);
					return "changePasswd";
				}
			} else {
				log.error("原密码不符，请重新核对 ");
				model.addAttribute("msg", "原密码不符，请重新核对 ");
				model.addAttribute("student", student);
				return "changePasswd";
			}
		}

		/**
		 * 修改密码
		 */
		int result = wishFillingService.changePassword(student);
		if (1 == result) {
			log.debug("密码修改成功");
		} else {
			log.warn("密码修改失败");
			model.addAttribute("student", student);
			return "changePasswd";
		}
		/**
		 * 跳转到登录界面重新登录
		 */
		return "loginStudent";
	}

	@RequestMapping(value = "forgetPwd", method = RequestMethod.POST)
	public String forgetPwd() {
		HttpSession session = wishFillingBiz.getSession();
		if (null == session || null == session.getAttribute("student")) {
			session = null;
			log.error("用户未登录，请重新登录");
			return "redirect:/";
		}
		return "forgetPasswd";
	}

	/**
	 * 特色项目及艺体特长报名页面（学生端）
	 * 
	 * @param model
	 * @return
	 */

	@RequestMapping(value = "artSpecialtySignUp")
	public String artSpecialtySignUp(Model model, @RequestParam("bmh") String bmh) {
		ResponseVo vo = new ResponseVo();
		/**
		 * 根据传入学生信息先判断是否已经报名，已经报名就显示已报名的信息供修改和确认
		 * 
		 */
		HttpSession session = wishFillingBiz.getSession();
		if (null == session || null == session.getAttribute("student")) {
			session = null;
			log.error("用户未登录，请重新登录");
			// return "redirect:/";
			vo.setCode("error");
			vo.setMessage("用户未登录，请重新登录");
			vo.setUrl("redirect:/");
		}

		SignUpStudent student = (SignUpStudent) session.getAttribute("student");
		// Map<String, Object> map = model.asMap();
		if (null == bmh || bmh.isEmpty()) {
			model.addAttribute("msg", "没接收到学生信息");
			// return "redirect:/";
			vo.setCode("error");
			vo.setMessage("用户未登录，请重新登录");
			vo.setUrl("redirect:/");
		}

		/**
		 * 报名时间判断 6月17日 18:00以前可用，18:00以后不可用
		 */
		Date day = new Date();

		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Date now = df.parse(df.format(day)); // 当前时间
			Date endTime = df.parse(tsyttbjssj); // 截止时间
			if (now.before(endTime)) {
				// 继续正常处理
				System.out.println("继续正常处理");

			} else {
				model.addAttribute("message", "非填报时间，不能报名");
				model.addAttribute("student", student);
				return "/transform";
			}
		} catch (Exception exception) {
			exception.printStackTrace();
			return "/transform";
		}

		WishOne wishOne = new WishOne();
		ArtSpecialtySignUp artSpecialtySignUp = wishFillingService.getArtSpeciatlyStudentByBmh(bmh);
		// SignUpStudent student = wishFillingService.getStudentByBmh(bmh);
		wishOne = wishFillingService.getWishOneSchool(student);
		if (null == artSpecialtySignUp || artSpecialtySignUp.getBmh().isEmpty()) {
			artSpecialtySignUp = new ArtSpecialtySignUp();
			artSpecialtySignUp.setBmh(student.getBmh());
			artSpecialtySignUp.setXm(student.getXm());
		} else {
			// artSpecialtySignUp.setBmh(bmh);
			// artSpecialtySignUp.setXm(artSpecialtySignUp.getXm());
			log.debug(artSpecialtySignUp.getGzxxdm());
			log.debug(artSpecialtySignUp.getBmh());
			log.debug(artSpecialtySignUp.getXm());

		}
		model.addAttribute("wishOne", wishOne);
		model.addAttribute("artSpecialtySignUp", artSpecialtySignUp);
		vo.setCode("ok");
		vo.setMessage("艺体特色页面报名跳转成功");
		vo.setUrl("wishFillingStudentTs");
		return "wishFillingStudentTs";
		// return vo;

	}

	/**
	 * 高中学校（第1，第2，第3批次）志愿报名页面（学生端）
	 * 
	 * @param model
	 * @return
	 */
	// @RequestMapping(value = "wishOneTwoThreeSignUp", method = RequestMethod.POST)
	public String wishOneTwoThreeSignUp(Model model, String bmh) {

		HttpSession session = wishFillingBiz.getSession();
		if (null == session || null == session.getAttribute("student")) {
			session = null;
			log.error("用户未登录，请重新登录");
			return "redirect:/";
		}
		SignUpStudent student = (SignUpStudent) session.getAttribute("student");
		model.addAttribute("student", student);
		// session.setAttribute("session", session);
		bmh = student.getBmh();
		if (null == bmh || bmh.isEmpty()) {
			model.addAttribute("msg", "没接收到学生信息");
			return "redirect:/";
		}
		/**
		 * 根据传入学生信息先判断是否已经报名，已经报名就显示已报名的信息供修改和确认
		 * 
		 */
		HighSchoolWish highSchoolWish = wishFillingService.getOneTwoThreeStudentByBmh(bmh);
		if (null == highSchoolWish) {
			log.warn("指定报名号的学生还没有第一批报名");

		}
		model.addAttribute("highSchoolWish", highSchoolWish);

		/**
		 * 根据学生报名表获取学生对应的第1，第2，第3批次可填报学校名单
		 */
		// SignUpStudent student = wishFillingService.getStudentByBmh(bmh);
		WishOne wishOne = wishFillingService.getWishOneSchool(student);
		WishTwo wishTwo = wishFillingService.getWishTwoSchool(student);
		WishThree wishThree = wishFillingService.getWishThreeSchool(student);
		WishAll wishAll = new WishAll();

		wishAll.setWishOne(wishOne);
		wishAll.setWishTwo(wishTwo);
		wishAll.setWishThree(wishThree);
		model.addAttribute("wishAll", wishAll);
		session.setAttribute("wishAll", wishAll);

		return "wishFillingStudent";

	}

	/**
	 * 中职学校（第4，第5，第6批次）志愿报名页面（学生端）
	 * 
	 * @param model
	 * @return
	 */
	// @RequestMapping(value = "wishFourFiveSixSignUp", method = RequestMethod.POST)
	public String wishFourFiveSixSignUp(Model model, String bmh) {

		HttpSession session = wishFillingBiz.getSession();
		if (null == session || null == session.getAttribute("student")) {
			session = null;
			log.error("用户未登录，请重新登录");
			return "redirect:/";
		}
		SignUpStudent student = (SignUpStudent) session.getAttribute("student");
		bmh = student.getBmh();
		if (null == bmh || bmh.isEmpty()) {
			model.addAttribute("msg", "没接收到学生信息");
			return "redirect:/";
		}
		/**
		 * 根据传入学生信息先判断是否已经报名，已经报名就显示已报名的信息供修改和确认
		 * 
		 */
		MiddleSchoolWish middleSchoolWish = wishFillingService.getFourFiveSixStudentByBmh(bmh);
		model.addAttribute("middleSchoolWish", middleSchoolWish);

		/**
		 * 根据学生报名表获取学生对应的第4，第5，第6批次可填报学校名单
		 */
		// SignUpStudent student = wishFillingService.getStudentByBmh(bmh);
		model.addAttribute("student", student);
		WishFour wishFour = wishFillingService.getWishFourSchool(student);
		WishFive wishFive = wishFillingService.getWishFiveSchool(student);
		WishSix wishSix = wishFillingService.getWishSixSchool(student);
		WishAll wishAll = new WishAll();

		wishAll.setWishFour(wishFour);
		wishAll.setWishFive(wishFive);
		wishAll.setWishSix(wishSix);
		model.addAttribute("wishAll", wishAll);

		return "/wishFillingStudent_second";

	}

	/**
	 * 特色项目及艺体特长报名（州教育局端）
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "test3", method = RequestMethod.GET)
	public String artSpecialtyCheckByState(Model model) {
		HttpSession session = wishFillingBiz.getSession();
		if (null == session || null == session.getAttribute("state")) {
			session = null;
			log.error("用户未登录，请重新登录");
			return "redirect:/";
		}
		// SignUpStudent student = (SignUpStudent) session.getAttribute("student");
		/**
		 * 查询所有已报名的学生信息
		 */
		List<ArtSpecialtySignUp> students = wishFillingService.getAllArtSpeciatlyStudent();
		model.addAttribute("students", students);
		return "wishFillingStateTs";
	}

	/**
	 * 特色项目及艺体特长报名（学生端）
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "doWishArtSpecialtyByStudent", method = RequestMethod.GET)
	public String wishArtSpecialtyByStudent(Model model) {
		HttpSession session = wishFillingBiz.getSession();
		if (null == session || null == session.getAttribute("state")) {
			session = null;
			log.error("用户未登录，请重新登录");
			return "redirect:/";
		}
		// SignUpStudent student = (SignUpStudent) session.getAttribute("student");
		/**
		 * 查询所有已报名的学生信息
		 */
		List<ArtSpecialtySignUp> students = wishFillingService.getAllArtSpeciatlyStudent();
		model.addAttribute("students", students);
		return "wishFillingStudentTs";
	}

	/**
	 * 特色项目、艺体生报名页面提交（报名数据保存）
	 * 
	 * @param param
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "saveArtSpecialty", method = RequestMethod.POST)
	@ResponseBody
	public ResponseVo saveArtSpecialtySignUp(SignUpPageData param, Model model) {
		ResponseVo vo = new ResponseVo();
		HttpSession session = wishFillingBiz.getSession();
		if (null == session || null == session.getAttribute("student")) {
			session = null;
			log.error("用户未登录，请重新登录");
			vo.setCode("error");
			vo.setMessage("用户未登录，请重新登录");
			vo.setUrl("/");
			return vo;

			/*
			 * session = null; log.error("用户未登录，请重新登录"); return "redirect:/";
			 */
		}
		// SignUpStudent student = (SignUpStudent) session.getAttribute("student");

		/**
		 * 将页面录入数据保存到报名对象中
		 */
		ArtSpecialtySignUp artSpecialtySignUp = new ArtSpecialtySignUp();
		artSpecialtySignUp.setBmh(param.getBmh());
		artSpecialtySignUp.setXm(param.getXm());
		artSpecialtySignUp.setGzxxdm(param.getGzxxdm());
		if (null == param.getGzxxdm() || param.getGzxxdm() == "") {
			artSpecialtySignUp.setGzxxmc("");
		} else {
			artSpecialtySignUp.setGzxxmc(param.getGzxxmc());
		}
		// artSpecialtySignUp.setGzxxmc(param.getGzxxmc());
		artSpecialtySignUp.setYtzydm(param.getYttcdm());
		if (null == param.getYttcdm() || param.getYttcdm() == "") {
			artSpecialtySignUp.setYtzymc("");
		} else {
			artSpecialtySignUp.setYtzymc(param.getYttcmc());
		}
		artSpecialtySignUp.setYttccl(param.getYttccl());

		/**
		 * 调用保存服务将艺体报名数据存往数据库
		 */
		int result = wishFillingService.saveArtSpecialtyYt(artSpecialtySignUp);
		model.addAttribute("artSpecialtySignUp", artSpecialtySignUp);
		if (1 == result) {

			/**
			 * 保存特色项目信息时清除艺体特长学校信息
			 */
			artSpecialtySignUp.setGzxxdm(null);
			artSpecialtySignUp.setGzxxmc(null);
			artSpecialtySignUp.setYtzydm(null);
			artSpecialtySignUp.setYtzymc(null);
			artSpecialtySignUp.setYtkhcj(null);
			artSpecialtySignUp.setYttccl(null);
			/**
			 * 设置特色项目学校信息
			 */
			artSpecialtySignUp.setGzxxdmts(param.getGzxxdmts());
			if (null == param.getGzxxdmts() || param.getGzxxdmts() == "") {
				artSpecialtySignUp.setGzxxmcts("");
			} else {
				artSpecialtySignUp.setGzxxmcts(param.getGzxxmcts());
			}
			// artSpecialtySignUp.setGzxxmcts(param.getGzxxmcts());
			artSpecialtySignUp.setTszydm(param.getTsxmdm());
			if (null == param.getTsxmdm() || param.getTsxmdm() == "") {
				artSpecialtySignUp.setTszymc("");
			} else {
				artSpecialtySignUp.setTszymc(param.getTsxmmc());
			}
			artSpecialtySignUp.setTsxmcl(param.getTsxmcl());
			artSpecialtySignUp.setTskhcj(null);
			/**
			 * 保存特色项目专业
			 */
			result = wishFillingService.saveArtSpecialtyTs(artSpecialtySignUp);
			if (1 == result) {
				/**
				 * 保存成功
				 */
				vo.setCode("ok");
				vo.setMessage("艺体特长报名数据保存成功！");
				vo.setUrl("/transforms");
				return vo;
				/*
				 * log.debug("艺体特长报名数据保存成功"); model.addAttribute("result", "艺体特长报名数据保存成功！");
				 * return "wishFillingStudentTs";
				 */
			} else {
				/**
				 * 保存失败，删除刚才已保存的数据
				 */
				wishFillingService.deleteArtSpecialtyYt(artSpecialtySignUp);
				/*
				 * log.error("艺体特长报名数据保存失败"); model.addAttribute("msg", "艺体特长报名数据保存异常，请重新提交！");
				 * return "wishFillingStudentTs";
				 */
				vo.setCode("error");
				vo.setMessage("艺体特长报名数据保存异常，请重新提交！");
				vo.setUrl("/transforms");
				return vo;
			}

		} else {
			/**
			 * 保存失败
			 */
			/*
			 * log.error("艺体特长报名数据保存失败"); model.addAttribute("msg", "艺体特长报名数据保存异常，请重新提交！");
			 * return "wishFillingStudentTs";
			 */
			vo.setCode("error");
			vo.setMessage("艺体特长报名数据保存异常，请重新提交！");
			vo.setUrl("/transforms");
			return vo;
		}

	}

	/**
	 * @Title: PageUserSelect @Description: 分页查询 @param pageNum 页数 @param Size
	 *         单页条数 @return PageInfo<User> @throws
	 */
	@RequestMapping("/PageUserSelect")
	@ResponseBody
	public PageInfo<HighSchool> PageUserSelect(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
			@RequestParam(value = "Size", defaultValue = "5") int Size) {
		Page<HighSchool> persons = wishFillingService.findByPage(pageNum, Size);
		PageInfo<HighSchool> pageInfo = new PageInfo<HighSchool>(persons);
		return pageInfo;
	}

	/**
	 * 获取当前访问URL路径
	 * 
	 * @return
	 */
	protected String getCurrentUrl() {
		String url = "";
		url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
				+ request.getServletPath();
		if (request.getQueryString() != null) {
			url += "?" + request.getQueryString();
		}
		log.debug(url);
		return url;
	}

	/**
	 * 查询录取状态页面
	 * 
	 * @return
	 */
	@RequestMapping("doQueryAdmission")
	public String queryAdmission(Model model, @RequestParam("bmh") String bmh) {

		HttpSession session = wishFillingBiz.getSession();
		if (null == session || null == session.getAttribute("student")) {
			session = null;
			log.error("用户未登录，请重新登录");
			return "redirect:/";
		}
		SignUpStudent student = (SignUpStudent) session.getAttribute("student");
		if (null == bmh || !bmh.equals(student.getBmh())) {
			session = null;
			log.error("用户请求数据不一致，请重新登录");
			return "redirect:/";
		}

		log.debug("进入【志愿填报页面】");
		if (null == student || null == student.getBmh() || student.getBmh().isEmpty()) {
			// model.addAttribute("student",student);
			log.warn("学生信息为空，需要重新登录");
			return "loginStudent";
		}

		model.addAttribute("student", student);

		/**
		 * 查录取状态
		 */
		Admission admission = wishFillingService.queryAdmissionByBmh(bmh);

		if (null == admission || null == student.getBmh() || null == admission.getBmh()
				|| !student.getBmh().equals(admission.getBmh())) {
			log.warn("学生信息与录取信息不匹配，需要重新登录");
			return "loginStudent";
		}

		model.addAttribute("admission", admission);

		return "queryAdmission";
	}

	// public static HttpSession getSession() {
	// HttpSession session = null;
	// try {
	// session = getRequest().getSession();
	// } catch (Exception e) {
	// }
	// return session;
	// }
	//
	// public static HttpServletRequest getRequest() {
	// ServletRequestAttributes attrs = (ServletRequestAttributes)
	// RequestContextHolder.getRequestAttributes();
	// return attrs.getRequest();
	// }
}
